<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>先花花</title>
    <link rel="stylesheet" href="css/jquery.mobile-1.4.5.min.css"/>
   	<link rel="stylesheet" href="css/style.css"/>
    <link rel="stylesheet" type="text/css" href="css/common.css" />

</head>
<body>
  <section>
 <div class="navigation-bar"> <a href="javascript:history.back(-1)" class="z-01"></a> <span>交易密码</span> <a href="index.html" class="z-02"></a> </div>
</section>
	<div data-role="page" class="touzi phone" id="phone">
		<header data-role="header" data-position="fixed">
		</header>
		<div class="ui-content" data-role="content">
			<form>
				<ul>
					<li>
						<label>手机号：</label>
						<input type="tel" placeholder="" data-role="none" id="mobileNumber"/>
            <input type="hidden" placeholder="" data-role="none" id="mobileNumber1"/>
						<input type="hidden" name="iphoneCode" id="iphoneCode" >
					</li>
          <p id="iphoneCodes" class="validateNew"></p>
					<li>
						<label>短信验证码：</label>
						<input type="num" placeholder="输入短信验证码" data-role="none" id="yzm" onblur="codes(this.value)" />
						<input type="button" value="发送验证码" data-role="none" onclick="sendYzm()" id="yzmcode" />
					</li>
						<p id="mobileNumberErrorDiv" class="validateNew"></p>
					<li>
						<label>新交易密码：</label>
						<input type="password" data-role="none" id="tradingPwd" name="tradingPwd"  onblur="pwd(this.value)"/>
					</li>
						<p id="pwdDiv" class="validateNew"></p>
					<li>
						<label>请再次输入：</label>
						<input type="password" data-role="none" name="qrtradingPwd" id="qrtradingPwd" onblur="qrpwd(this.value)"/>
					</li>
						<p id="qrpwdDiv" class="validateNew"></p>
				</ul>
				<input type="button" value="确认修改" data-role="none" onclick="but()" />
			</form>
		</div>
		<script src="script/jquery.js"></script>
    <script src="script/common.js"></script>
    <script type="text/javascript" src="script/jquery.cookie.js"></script>
    <script type="text/javascript" src="script/jquery.md5.js"></script>
	</div>
</body>
</html>
<script>
  flag1=false;
  flag2=false;
  flag3=false;
  flag4=false;
  $(function(){
      $.ajax({
          url:commonUrl+"/Userinfo/index",
          data:{appid:appid,appkey:appkey,uid:uid},
          type:"get",
          dataType:"jsonp",
          jsonp:"callback",
          success:function(result){
            $("#mobileNumber").val(result.data.tel1);
            $("#mobileNumber").attr("disabled",true);
            $("#mobileNumber1").val(result.data.account);
          }
      });
  })
//发送验证码
function sendYzm(){
  //手机号
  var mobileNumber=$("#mobileNumber1").val();
  $.ajax({
        url:commonUrl+'/sendmessage/index',
        type:'post',
        dataType:'jsonp',
        jsonp:"callback",
        data:{
          tel:mobileNumber,appkey:appkey,appid:appid
        },
        success:function(result){
            if(result.SubmitResult.code == 2) {
              //alert(result.data.code);
              $("#iphoneCode").val(result.code);
              count = 0
              int = setInterval(time,1000)

            } else {
              alert('please check you iphone number');
            }
        }
    });
}
function time()
{
  a=60-count;
  $('#yzmcode').val(a)
  if(count == 60)
  {
    clearInterval(int)
    $("#yzmcode").val('发送验证码')
  }
    count++;
}
//校验手机号码
function tel(str) {
    var reg = /^1[3578]\d{9}$/.test(str);
    if(str==''){
        $('#iphoneCodes').html("<font color='red'>请输入手机号！</font>");
        return false;
    }
    if(!reg){
        $('#iphoneCodes').html("<font color='red'>手机格式不正确！</font>");
        return false;
    }else{
      $('#iphoneCodes').html("<font color='green'>OK！</font>");
      flag1=true;
      return true;
    }
}
//验证码
function codes(str){
    var iphoneCode=$('#iphoneCode').val();
    if(str == ""){
    		$('#mobileNumberErrorDiv').html("<font color='red'>请填写验证码</font>");
            return false
        }else if(str == iphoneCode){
          flag2=true;
        	$('#mobileNumberErrorDiv').html("<font color='green'>验证成功</font>");
        }else{
        	$('#mobileNumberErrorDiv').html("<font color='red'>验证码填写错误</font>");
            return false
        }
}
//支付密码校验
function pwd(str){
	var reg = /^\d{6}$/.test(str);
  var reg1 = /^\S+$/gi.test(str);
	if(str ==''){
		$('#pwdDiv').html("<font color='red'>请输入支付密码！</font>");
        return false
	}
	if(reg&&reg1){
		$('#pwdDiv').html("<font color='green'>输入支付密码合法</font>");
        flag3=true;
	}else{
		$('#pwdDiv').html("<font color='red'>请输入合法支付密码</font>");
		return false
	}
}
//确认支付密码校验
function qrpwd(){
	var tradingPwd=$('#tradingPwd').val();
	var qrtradingPwd=$('#qrtradingPwd').val();
  if(qrtradingPwd == ''){
    $('#qrpwdDiv').html("<font color='red'>确认密码不能为空</font>");
    return false;
  }
	if(tradingPwd == qrtradingPwd){
		$('#qrpwdDiv').html("<font color='green'>输入支付密码相同</font>");
		flag4=true;
	}else{
		$('#qrpwdDiv').html("<font color='red'>请输入相同支付密码</font>");
    return false;
	}
}
//修改交易密码
function but(){
  if(flag1&&flag2&&flag3&&flag4){
  var tradingPwd = $.md5($("#tradingPwd").val());
	$.ajax({
          url:commonUrl+"/Userinfo/updatePaypwd",
          data:{appid:appid,appkey:appkey,uid:uid,pwd:tradingPwd},
          type:"get",
          dataType:"jsonp",
          jsonp:"callback",
          success:function(result){
            alert(result.msg)
            window.location.href='user.html';
          }
      });
    }
}
</script>
</html>
